package com.syj.collect.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.syj.collect.app.AllActivity;
import com.syj.collect.app.R;
import com.syj.collect.base.BaseFragment;
import com.syj.collect.entry.UserInfoBean;
import com.syj.collect.http.ApiServise;
import com.syj.collect.model.MyCollectActivity;
import com.syj.collect.model.MyMonthActivity;
import com.syj.collect.model.MyPhontoActivity;
import com.syj.collect.model.MyTaskActivity;
import com.syj.collect.model.MyUserActivity;
import com.syj.collect.utils.GlideUtils;
import com.syj.collect.utils.GsonUtil;
import com.syj.collect.utils.HttpUtils;
import com.syj.collect.utils.LogUtils;
import com.syj.collect.utils.SPUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class MyFragment extends BaseFragment {

    @BindView(R.id.rl_user)
    RelativeLayout rlUser;
    @BindView(R.id.ll_month)
    LinearLayout llMonth;
    @BindView(R.id.ll_task)
    LinearLayout llTask;
    @BindView(R.id.ll_phono)
    LinearLayout llPhono;
    @BindView(R.id.ll_collect)
    LinearLayout llCollect;
    @BindView(R.id.all_f)
    TextView all_f;
    @BindView(R.id.fname)
    TextView name;
    @BindView(R.id.iv_head)
    ImageView ivhead;
    Unbinder unbinder;
    private UserInfoBean.UserInfo userInfo;

    @Override
    protected int getLayoutId() {
        return R.layout.fargment_my;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }



    @Override
    public void onResume() {
        super.onResume();
//        LogUtils.i("asdsdasdsafsafsafsaffasfasss");
        String userbean = SPUtil.getPrefString("userInfo", "");
        Gson gson = new Gson();
        userInfo = gson.fromJson(userbean, UserInfoBean.UserInfo.class);
        name.setText(userInfo.getName());
        GlideUtils.Image(ivhead, ApiServise.BASEURLFILE+userInfo.getIconUrl());
    }

    @OnClick({R.id.rl_user, R.id.ll_month, R.id.ll_task, R.id.ll_phono, R.id.ll_collect, R.id.all_f})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_user:
                //yonghu
                startActivity(new Intent(getActivity(), MyUserActivity.class));
                break;
            case R.id.ll_month:
                //yuebao
                startActivity(new Intent(getActivity(), MyMonthActivity.class));
                break;
            case R.id.ll_task:
                //renwu
                Intent intent = new Intent(getActivity(), MyTaskActivity.class);
                intent.putExtra("ttype", 1);
                startActivity(intent);
                break;
            case R.id.ll_phono:
                //zhaopian
                startActivity(new Intent(getActivity(), MyPhontoActivity.class));
                break;
            case R.id.ll_collect:
                //shoucang
                startActivity(new Intent(getActivity(), MyCollectActivity.class));
                break;
            case R.id.all_f:
                startActivity(new Intent(getActivity(), AllActivity.class));
                break;
        }
    }
}
